//
//  HLMainController.swift
//  HLwWeibo
//
//  Created by hqhxu on 16/2/26.
//  Copyright © 2016年 hqhxu. All rights reserved.
//

import UIKit

class HLMainController: UITabBarController,HLtabBarDelegate {

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        addChildViewController()
        
        let mainTabaBar = HLTabBar()
        
        mainTabaBar.mainTabBarDelegate = self
        
        setValue(mainTabaBar, forKeyPath: "tabBar")
        
        
        
        //这是一个全局的属性  获取全局的直接获取 不要和oc中使用方法获取了
//        tabBar.tintColor = UIColor.orangeColor()
    }
    
    // MARK - 实现dialing方法
    func tabBarDidClick(button: UIButton) {
        
        self.presentViewController(UINavigationController(rootViewController: HLConposeViewController()), animated: true, completion: nil)
    }
    
    /// 添加自控制器
    func addChildViewController() {
        let homeVC = HLHomeController()
        setController(homeVC, title: "首页", imageNmae: "tabbar_home")
        
        let messageVC = HLMessageController()
        setController(messageVC, title: "消息", imageNmae: "tabbar_message_center")
        
        let placeVC = UIViewController()
        addChildViewController(placeVC)
        
        let discoverVC = HLDiscoverController()
        setController(discoverVC, title: "发现", imageNmae: "tabbar_discover")
        
        let profileVC = HLProfileController()
        setController(profileVC, title: "我", imageNmae: "tabbar_profile")
    }
    
    /// 设置自控制器的相应属性
    func setController(controller:UIViewController,title:String?,imageNmae:String) {
        
        controller.title = title
        
        
        controller.tabBarItem.image = UIImage(named: imageNmae)
        
        let selectedImageName = imageNmae + "_highlighted"
        
        controller.tabBarItem.selectedImage = UIImage(named: selectedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
        let navVC = UINavigationController(rootViewController: controller)
        
        addChildViewController(navVC)
    }
    
}
